<template>
  <a-modal
    class="check-modal"
    :title="title"
    width="100%"
    :visible="visible"
    :confirmLoading="confirmLoading"
    :destroyOnClose="true"
    @cancel="handleCancel"
  >
    <template v-if="activeIndex != 3">
      <template slot="footer">
        <a-button @click="handleCancel">关闭</a-button>
      </template>
      <a-table
        :columns="columns"
        :data-source="dataSource"
        row-key="id"
        :loading="loading"
        :pagination="ipagination"
        :scroll="{ x: 5000 }"
      >
      </a-table>
    </template>
    <template v-else>
      <template slot="footer">
        <a-button @click="handleCancel">关闭</a-button>
        <a-button type="primary" @click="handleSave" :disabled="selectedRows.length <= 0">保存</a-button>
      </template>
      <a-table
        :columns="columns"
        :data-source="dataSource"
        row-key="id"
        :loading="loading"
        :pagination="ipagination"
        :scroll="{ x: 3600 }"
        :row-selection="rowSelection"
      >
      </a-table>
    </template>
  </a-modal>
</template>

<script>
import { JeecgListMixin } from '@/mixins/JeecgListMixin'
import { tableColumns1, tableColumns2, tableColumns3, tableColumns4 } from './tableColumns'
import { httpAction, getAction, postAction, deleteAction } from '@/api/manage'
export default {
  name: 'CheackDetail',
  mixins: [JeecgListMixin],
  data() {
    return {
      title: '',
      visible: false,
      confirmLoading: false,
      queryParam: {},
      url: {
        list: '',
        save: '/sjmx2Test/saveBalance'
      },
      lists: ['/sjmx2Test/queryYhclje', '/sjmx2Test/querySjfscbje', '/sjmx2Test/queryZmcbze', '/sjmx2Test/queryFrdbwz'],
      loading: false,
      columns: [],
      dataSource: [],
      activeIndex: 0,
      disableMixinCreated: true,
      selectedRowKeys: [''],
      selectedRows: []
    }
  },
  computed: {
    // 行选择
    rowSelection() {
      return {
        type: 'radio',
        selectedRowKeys: this.selectedRowKeys,
        onChange: (selectedRowKeys, selectedRows) => {
          this.selectedRowKeys = [...selectedRowKeys]
          this.selectedRows = [...selectedRows]
          console.log(selectedRowKeys, selectedRows)
        }
      }
    }
  },
  methods: {
    check(index, params, record) {
      this.queryParam = { ...params }
      this.url.list = this.lists[index]
      this.activeIndex = index
      switch (index) {
        case 0:
          this.title = '应耗材料金额'
          this.columns = tableColumns1(this)
          break
        case 1:
          this.title = '实际发生成本金额'
          this.columns = tableColumns2(this)
          break
        case 2:
          this.title = '账面成本总额'
          this.columns = tableColumns3(this)
          break
        case 3:
          this.title = '法人内调拨物资列表'
          this.columns = tableColumns4(this)
          this.selectedRowKeys = [record.balanceId]
          break
      }
      this.loadData(1)
      this.visible = true
    },
    handleSave() {
      debugger
      postAction(this.url.save, { balanceId: this.selectedRows[0].id, xmbmc: this.selectedRows[0].orgNm })
        .then(res => {
          if (res.success) {
            this.handleCancel()
            this.$emit('RelaodData')
            this.$message.success(res.result)
          } else {
            this.$message.error(res.result)
          }
        })
        .catch(err => {})
    },
    handleCancel() {
      this.selectedRowKeys = []
      this.selectedRows = []
      this.visible = false
    }
  }
}
</script>

<style lang="less" scoped>
@import '~@assets/less/tableTheme.less';
.check-modal {
  top: 0;
  left: 0;
  padding: 0;

  // 兼容1.6.2版本的antdv
  /deep/.ant-modal {
    top: 0;
    padding: 0;
    height: 100vh;
  }

  /deep/.ant-modal-content {
    height: 100vh;
    border-radius: 0;

    & .ant-modal-body {
      /* title 和 footer 各占 55px */
      height: calc(100% - 55px - 55px);
      overflow: auto;
    }
  }

  /deep/.no-title,
  /deep/.no-footer {
    .ant-modal-body {
      height: calc(100% - 55px);
    }
  }
  /deep/.no-title.no-footer {
    .ant-modal-body {
      height: 100%;
    }
  }
}
</style>
